package 第一章基础算法.前缀和与差分.id796子矩阵的和;

import java.util.Scanner;

/**
 * 二维前缀和
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int q = scanner.nextInt();
        int[][] matrix = new int[n][m];
        for(int i = 0;i<n;i++){
            for(int j = 0;j<m;j++){
                matrix[i][j] = scanner.nextInt();
            }
        }
        //处理出二维前缀和
        int[][]pre = new int[n+1][m+1];
        for(int i = 1;i<=n;i++){
            for(int j = 1;j<=m;j++){
                pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1] + matrix[i-1][j-1];
            }
        }
        while (q-- >0){
            //第一次减一得到原矩阵中的下标，加一得到前缀矩阵中的下标
            int x1 = scanner.nextInt()-1+1;
            int y1 = scanner.nextInt()-1+1;
            int x2 = scanner.nextInt()-1+1;
            int y2 = scanner.nextInt()-1+1;
            int res = pre[x2][y2] - pre[x2][y1-1] - pre[x1-1][y2] + pre[x1-1][y1-1];
            System.out.println(res);
        }
    }
}
